package com.ckzp.jfinal.system.controller;

import com.ckzp.core.json.JsonResult;
import com.ckzp.jfinal.base.BaseController;
import com.ckzp.jfinal.form.FormData;
import com.ckzp.jfinal.interceptor.Admins;
import com.ckzp.jfinal.interceptor.Roles;
import com.ckzp.jfinal.system.util.SysCacheUtil;

/**
 * Created by 51594 on 2022/3/28.
 */
public class SysCacheController extends BaseController {

    @Admins(roles = "system", name = "默认", log = false)
    public void index() {
        renderText("默认");
    }


    /**
     * 缓存查看页面
     */
    @Admins(roles = "system", name = "缓存查看页面", log = false)
    public void SysCacheList() {
        FormData fd = FormData.dao();
        setAttr("form", fd);
        render("SysCacheList.html");
    }

    /**
     * 取缓存空间API
     */
    @Admins(roles = "system", name = "取缓存空间API", log = false)
    public void getCacheSpaceApi() {
        renderJson(JsonResult.n(0, "成功").setData(SysCacheUtil.getCacheSpaceInfo()));
    }

    /**
     * 取缓存KeyAPI
     */
    @Admins(roles = "system", name = "取缓存KeyAPI", log = false)
    public void getCacheKeysApi() {
        String space = getParaStr("space", "");
        renderJson(JsonResult.n(0, "成功").setData(SysCacheUtil.getCacheKeysInfo(space)));
    }

    /**
     * 取缓存值API
     */
    @Admins(roles = "system", name = "取缓存值API", log = false)
    public void getCacheValueApi() {
        String space = getParaStr("space", "");
        String key = getParaStr("key", "");
        renderJson(JsonResult.n(0, "成功").setData(SysCacheUtil.getCacheValueInfo(space, key)));
    }

    /**
     * 删除缓存API
     */
    @Admins(roles = "system", name = "删除缓存API", log = false)
    public void DelCacheApi() {
        String space = getParaStr("space", "");
        String key = getParaStr("key", "");
        renderJson(JsonResult.n(0, "成功").setData(SysCacheUtil.delCache(space, key)));
    }


}

